package com.jy.datapipeline.importserver.handler;

import com.jy.datapipeline.common.util.BeanFactoryUtil;
import com.jy.datapipeline.importserver.service.ImportTaskService;
import lombok.SneakyThrows;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Date;

/**
 * @类名 CornTabHandler
 * @描述 TODO
 * @作者 白条君
 * @创建日期 2023/4/19 17:59
 * @版本 1.0
 */
public class ScheduleTaskHandler extends QuartzJobBean {

    @SneakyThrows
    @Override
    protected void executeInternal(JobExecutionContext context) {
        ImportTaskService importTaskService = BeanFactoryUtil.getBean(ImportTaskService.class);

        //获取任务的id
        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
        String taskId = (String) jobDataMap.get("id");

        Date nextFireTime = context.getTrigger().getNextFireTime();

        importTaskService.startTask(taskId, nextFireTime);
    }
}
